define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/ordergoods/index' + location.search,
                    add_url: 'shop/ordergoods/add',
                    edit_url: 'shop/ordergoods/edit',
                    del_url: 'shop/ordergoods/del',
                    multi_url: 'shop/ordergoods/multi',
                    import_url: 'shop/ordergoods/import',
                    table: 'shop_ordergoods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'goods_info', title: __('Goods_info')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'pay_price', title: __('Pay_price'), operate:'BETWEEN'},
                        {field: 'total', title: __('Total')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.id', title: __('Order.id')},
                        {field: 'order.order_no', title: __('Order.order_no'), operate: 'LIKE'},
                        {field: 'order.user_id', title: __('Order.user_id')},
                        {field: 'order.custom_id', title: __('Order.custom_id')},
                        {field: 'order.status', title: __('Order.status'), formatter: Table.api.formatter.status},
                        {field: 'order.total', title: __('Order.total')},
                        {field: 'order.total_fee', title: __('Order.total_fee'), operate:'BETWEEN'},
                        {field: 'order.pay_fee', title: __('Order.pay_fee'), operate:'BETWEEN'},
                        {field: 'order.pay_time', title: __('Order.pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.finished_time', title: __('Order.finished_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.remark', title: __('Order.remark'), operate: 'LIKE'},
                        {field: 'order.consign_name', title: __('Order.consign_name'), operate: 'LIKE'},
                        {field: 'order.consign_mobile', title: __('Order.consign_mobile'), operate: 'LIKE'},
                        {field: 'order.consign_address', title: __('Order.consign_address'), operate: 'LIKE'},
                        {field: 'order.pay_image', title: __('Order.pay_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'order.createtime', title: __('Order.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.updatetime', title: __('Order.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.deletetime', title: __('Order.deletetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.express_com', title: __('Order.express_com')},
                        {field: 'order.express_no', title: __('Order.express_no'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
